@extends('layouts.app')
@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-3">
                <div class="card">
                    <div class="card-body">
                        <img src="{{asset("storage/".$user->image)}}" class="card-img-top"/>
                        <span class="card-title mt-2"> {{$user->name}}</span>
                        <p class="card-text">{{$user->introduction}}</p>
                        <div class="row mt-2">

                            <div class="row-4">
                                <div class="col">
                                    <span class="d-block">关注</span>
                                    <span class="d-block">{{$user->followings()->count()}}</span>
                                </div>
                            </div>

                            <div class="row-4">

                                <div class="col">
                                    <span class="d-block">粉丝</span>
                                    <span class="d-block">{{$user->followers()->count()}}</span>
                                </div>
                            </div>

                            <div class="row-4">

                                <div class="col">
                                    <span class="d-block">文章</span>
                                    <span class="d-block">{{$user->posts()->count()}}</span>
                                </div>
                            </div>
                        </div>
                        <div class="mt-3">

                            {{--@can('update',$user)--}}
                                {{--<a class="btn btn-primary btn-sm" href="{{route('users.edit',$user)}}">编辑</a>--}}
                            {{--@endcan--}}

                            @can('destroy',$user)
                                <form class="d-inline-block" action="{{route('users.destroy',$user->id)}}"
                                      method="post">
                                    {{method_field('DELETE')}}
                                    {{csrf_field()}}
                                    <div class="form-group">
                                        <input class="btn btn-danger" type="submit" value="删除">
                                    </div>
                                </form>
                            @endcan
                        </div>


                        @can('follow',$user)

                            @if(Auth::user()->isFollowing($user->id))

                                <form action="{{route('unfollow',$user->id)}}" method="post">
                                    {{csrf_field()}}
                                    {{method_field('DELETE')}}
                                    <input type="submit" class="btn btn-primary"
                                           value="取消关注">

                                </form>
                            @else

                                <form action="{{route('follow',$user->id)}}" method="post">
                                    {{csrf_field()}}
                                    <input type="submit" class="btn btn-primary"
                                           value="关注">

                                </form>
                            @endif

                        @endcan

                        <hr>

                        <h4>注册于</h4>
                        <span>{{$user->created_at->diffForHumans()}}</span>
                        <h4>最近在线</h4>
                        <span>{{$user->last_login_time}}</span>
                    </div>
                </div>
            </div>

            <div class="col-md-9 mt-2 mt-md-0">
                @include('layouts.post_list')
            </div>

        </div>
    </div>
@endsection
